<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-inline">
                                <input id="iid" type="text" name="iid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">发起人姓名</label>
                            <div class="layui-input-inline">
                                <input id="ename" type="text" name="ename" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">供应商公司</label>
                            <div class="layui-input-inline">
                                <input id="firm" type="text" name="firm" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="switchTpl">
            <input type="checkbox" name="manager" value="{{d.iid}}" lay-skin="switch" lay-text="同意购买|未审批" lay-filter="switchTest" {{ d.payment == 1 ? 'checked' : '' }}>
        </script>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">Pass</a>
        </script>

        <%--        经理人审批状态--%>
        <script type="text/html" id="managerTpl">
            {{#  if(d.manager === 1){ }}
            <span style="color: #02DF82;;">同意</span>
            {{#  } else { }}
            未审批
            {{#  } }}
        </script>

        <%--        付款状态--%>
        <script type="text/html" id="paymentTpl">
            {{#  if(d.payment === 1){ }}
            <span style="color: #FF5809;">同意购买</span>
            {{#  } else if(d.payment === 2){ }}
            <span style="color: #02DF82;">已付款</span>
            {{#  } else { }}
            未审批
            {{#  } }}
        </script>


        <%--        保管员接收状态--%>
        <script type="text/html" id="receiveTpl">
            {{#  if(d.receive === 1){ }}
            <span style="color: #02DF82;;">核对完成</span>
            {{#  } else { }}
            未接收
            {{#  } }}
        </script>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../../jquery-3.3.1.js" charset="UTF-8"></script>
<script>
    layui.use(['form', 'table', 'util'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            util = layui.util;

        table.render({
            elem: '#currentTableId',
            url: '/indent/bosslist',
            toolbar: '#toolbarDemo',
            escape: true,
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {width:20},
                {field: 'iid', minWidth:1, title: '订单编号', sort: true},
                {field: 'ename', minWidth:1, title: '发起人'},
                {field: 'cname', minWidth:1, title: '商品名称'},
                {field: 'tname',minWidth:1, title: '商品类型'},
                {field: 'price', minWidth:1, title: '单价',templet:function (d) {
                        return d.price+'元/'+d.mbig
                    }},
                {field: 'scale', minwidth: 90, title: '规格',templet:function (d) {
                        return d.scale+d.mlittle+"/"+d.mbig
                    }},
                {field: 'firm',minWidth:1, title: '供应商公司'},
                {field: 'num', minWidth:1, title: '采购数量', sort: true,edit:'text'},
                {field: 'expense',minWidth:1, title: '所需金额', sort: true,templet:function (d) {
                        return d.price*d.num+'元'
                    }},
                {field: 'manager', Width:250, title: '经理人审批',templet: '#managerTpl', unresize: true},
                {field: 'payment', minWidth:1, title: '付款状态',templet:'#switchTpl'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]], page:true,
            limits: [5,10, 15]
            , limit: 10
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                }
                else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
        });

        //监听单元格编辑
        table.on('edit(currentTableFilter)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            $.post(
                "/indent/indentUpdNum",{
                    iid:data.iid,
                    num:util.escape(value)
                },function () {
                    location.reload()
                }
            )

        });
        //监听经理审批
        form.on('switch(switchTest)', function(obj){
            $.post(
                "/indent/examineUpd",{
                    iid:this.value,
                    payment:obj.elem.checked?1:0,
                    rank:obj.elem.checked?2:1
                },function () {
                    location.reload()
                }
            ),
                {
                    offset: '6px'
                }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    iid:$("#iid").val(),
                    ename:$("#ename").val(),
                    firm:$("#firm").val(),
                }
            }, 'data');
            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
           if (obj.event === 'delete') {
                layer.confirm('确认取消订单么', function (index) {
                    $.post(
                        "/indent/del",{
                            iid:data.iid
                        },function () {
                            layer.close(index)
                            layer.msg("供应商已同意，取消订单成功",function () {
                                location.reload()
                            })
                        }
                    )
                });
            }
        });

    });
</script>

</body>
</html>